import express from "express";
import history from "connect-history-api-fallback";
import router from "./router.js";
import bodyParser from "body-parser";
import compression from "compression";
import multer from "multer";
let objMulter = multer({ dest: "./public/upload" }); //实例化multer，传递的参数对象，dest表示上传文件的存储路径
// import fs from "fs";
const app = express();
app.use(history({ index: "index.html" }));
app.use(compression()); //gzip
app.use(objMulter.any()); //any表示任意类型的文件
app.use(express.static("public", { index: "index.html" }));
// 解析 application/x-www-form-urlencoded 格式
app.use(bodyParser.urlencoded({ extended: false }));
// 解析 application/json 格式
app.use(bodyParser.json());
app.use(router);

app.listen(3000, () => {
  console.log("启动成功 端口:\x1B[36m 3000 \x1B[0m");
});
